<?php

namespace app\admin\controller;

use app\common\controller\Send;
use app\admin\model\TieBaComment AS CommentModel;

class TieBaComment extends Base
{
    use Send;

    public function index()
    {
        $tieId = input('tieId');
        $model = CommentModel::getList($tieId);
        $detailType = input('detailType');
        $oauthId = input('oauth_id');
        switch ($detailType) {
            case 2:
                $title = '我的帖子';
                $url = url('tie_ba/mine', ['oauth_id' => $oauthId]);
                break;
            case 3:
                $title = '收藏帖子';
                $url = url('tie_ba_collect/index', ['oauth_id' => $oauthId]);
                break;
            default:
                $title = '帖子';
                $url = url('tie_ba/index');
                break;
        }
        return view('index', [
            'tieId' => $tieId,
            'model' => $model['model'],
            'count' => $model['count'],
            'title' => $title,
            'url' => $url,
        ]);
    }

    /**
     * 删除
     * @param $id
     * @return array
     */
    public function delete($id)
    {
        $model = CommentModel::get($id);
        $tieId = 0;
        if ($model) {
            $tieId = $model['tie_id'];
            $model->delete();
        }

        return self::sendResult(self::$okCode, [
            'url' => url('index', [
                'tieId' => $tieId,
            ]),
        ]);
    }
    
    public function deletes()
    {
        $tieId = input('tieId');
        $ids = input('ids');
        CommentModel::deleteAll($ids);

        return self::sendResult(self::$okCode, [
            'url' => url('index', [
                'tieId' => $tieId,
            ]),
        ]);
    }
}
